<?php
declare (strict_types = 1);

namespace app\admin\controller;

// use think\Request;
use think\facade\Db;
use think\facade\Cache;
use think\facade\Request;
use think\facade\Config;
use app\middleware\AuthAdmin;

class Apply{
    
    protected $middleware = [AuthAdmin::class];

    public function getDataByActivityId(){
        if(Request::isPost()){
            $activityId=input('param.activityId/s',0);

            $activity=new \app\index\controller\Activity();
            $activity=$activity->getActivityById($activityId);
            $dateRange=($activity['end_time']-$activity['start_time'])/86400;
            $tabs=[];
            for($i=0;$i<$dateRange;$i++){
                array_push($tabs,['date'=>date('Y-m-d',strtotime("+$i days",$activity['start_time']))]);
            }
             $result=['code'=>200,'message'=>'获取成功','success'=>true,'result'=>['tabs'=>$tabs,'detail'=>$activity]];
            return json($result);
        }
    }

    public function getListByActivityId(){
        if(Request::isPost()){
            $activityId=input('param.activityId/s',0);
            $page=input('param.page/s',0);
            $size=input('param.size/s',20);
            $bookingDate=input('param.bookingDate','');
            $keyword=input('param.keyword','');
            $where=[];
            if($bookingDate){
                $where[]=['booking_date','=',$bookingDate];
            }
            if($keyword){
                $where[]=['mobile|true_name','like',"%".$keyword."%"];
            }
            $data=Db::table('apply')->field('id,mobile,true_name,nickname,booking_date,accompany,remark')
            ->where($where)->order('create_at desc')
            ->paginate([
                'list_rows' => $size,
                'page'      => $page
            ]);
            $total=$data->total();
            $data=$data->items();
            $page_count=ceil($total/$size);
            $result=['code'=>200,'message'=>'获取成功','success'=>true,'result'=>['list'=>$data,'total'=>$total,'page'=>['current'=>$page,'size'=>$size,'total'=>$page_count]]];
            return json($result);
        }
    }
}